/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Br.Com.Cds.Academia.View;

import Br.Com.Cds.Academia.Exercicio.ExercicioBean;
import Br.Com.Cds.Academia.Exercicio.ExercicioControl;
import java.awt.Dimension;
import java.awt.Image;
import java.io.File;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author p
 */
public class TelaCadastroExercicio extends javax.swing.JFrame {
    
    DefaultTableModel tmExercicios = new DefaultTableModel(null,new String[]{"Exercício"}); 
    ListSelectionModel lsmExercicios; 
    String tipoCadastro; 
    List <ExercicioBean> exercicios;
    
    private void listarExercicios(){ 

        ExercicioControl exe = new ExercicioControl();
        exercicios = exe.listarExercicio("%" + TFpesquisarexercicio.getText().trim() + "%");
        mostrarExercicios(exercicios);

    }
        
        private void mostrarExercicios(List<ExercicioBean> exercicios){ 
        if ( exercicios.isEmpty()){                        
            tmExercicios.setRowCount(0);
            JOptionPane.showMessageDialog(this,"Registro Não Encontrado!","CDS ACADEMIA",JOptionPane.INFORMATION_MESSAGE);
        }else{                                       
            while(tmExercicios.getRowCount() > 0){
                  tmExercicios.removeRow(0);

            }
            String[] campos = new String[] { null}; 
            for (int i = 0;i < exercicios.size(); i++){   
                tmExercicios.addRow(campos);               
                tmExercicios.setValueAt(exercicios.get(i).getDescricao(),i,0);
  
            }
        }

    }
        
         private void tbExerciciosLinhaSelecionada(JTable tb){     

        if(tb.getSelectedRow() != -1){                      
            TFdescricaoexercicio.setText(exercicios.get(tb.getSelectedRow()).getDescricao());
            TFGrupoMuscular.setText(exercicios.get(tb.getSelectedRow()).getGrupomuscular());
            TFCaminhovideo.setText(exercicios.get(tb.getSelectedRow()).getCaminhovideo());
            String pegaStatus = exercicios.get(tb.getSelectedRow()).getStatus(); 
            if(pegaStatus.equals("ATIVO")){                
               JRBativoexercicio.setSelected(true);
               JRBinativoexercicio.setSelected(false);
            }else if(pegaStatus.equals("INATIVO")){
               JRBinativoexercicio.setSelected(true);
               JRBativoexercicio.setSelected(false);
            }

            BTalterarcadastro.setEnabled(true);    
            BTnovocadastro.setEnabled(true);       
            BTsalvarcadastro.setEnabled(false);


       }else{ // Se não houver nenhuma linha selecionada, deixa os campos em branco.
          
            TFdescricaoexercicio.setText("");
            JRBativoexercicio.setSelected(false);
            JRBinativoexercicio.setSelected(false);
            BTalterarcadastro.setEnabled(false);

       }

    }
         
         public void limpaTabela(){  
    DefaultTableModel tblRemove = (DefaultTableModel)TBtabelaexercicio.getModel();  
      
    if (tblRemove.getRowCount() > 0){  
        for (int i=1;i<=tblRemove.getRowCount();i++){  
            tblRemove.removeRow(0);  
        }              
    }  
  
}  
         
         public void buscaCaminho()
    {
       JFileChooser fc = new JFileChooser();
       fc.setCurrentDirectory(new File("C://"));
       fc.setFileFilter(new FileNameExtensionFilter("AVI, MPEG, WMV E MP4", "avi", "mpeg", "wmv","mp4"));
       int res = fc.showOpenDialog(null);

        if(res == JFileChooser.APPROVE_OPTION)
        {
            File arquivo = fc.getSelectedFile();
           // JOptionPane.showMessageDialog(null,"Você escolheu o arquivo: " + arquivo.getName());
           

                String Imc = arquivo.getPath();
                TFCaminhovideo.setText(Imc);       
        }
        else
        {
           JOptionPane.showMessageDialog(null,"VOCÊ NÃO SELECIONOU NENHUM ARQUIVO!","CDS ACADEMIA",JOptionPane.INFORMATION_MESSAGE);
        }
    }

          private JTable getJTable() {        //Metódo para definir o tamanho das colunas na JTable.
     if (TBtabelaexercicio == null) {
         TBtabelaexercicio = new JTable(tmExercicios);
         defineRenderers();
   }       return TBtabelaexercicio;
   
 }
         
          private void defineRenderers() {
     DefaultTableCellRenderer rendererCentro = new DefaultTableCellRenderer();
     rendererCentro.setHorizontalAlignment(SwingConstants.CENTER);
     DefaultTableCellRenderer rendererDireita = new DefaultTableCellRenderer();
     rendererDireita.setHorizontalAlignment(SwingConstants.RIGHT);
     DefaultTableCellRenderer rendererEsquerda = new DefaultTableCellRenderer();
     rendererEsquerda.setHorizontalAlignment(SwingConstants.LEFT);

     JTableHeader header = TBtabelaexercicio.getTableHeader();
     header.setPreferredSize(new Dimension(0, 35));
     TableColumnModel modeloDaColuna = TBtabelaexercicio.getColumnModel();
     
    // Aqui se define se o texto vai ficar no meio ou nos cantos da coluna.
     
     modeloDaColuna.getColumn(0).setCellRenderer(rendererCentro); 

   // Aqui se define o tamanho das colunas.
     
     modeloDaColuna.getColumn(0).setMaxWidth(1000);

 }
          
          private void novoExercicio(){ // Metodo para quando clicar no botão novo, habilitar e limpar os campos

      TFCaminhovideo.setText("");
      TFGrupoMuscular.setText("");
      TFdescricaoexercicio.setText("");
      JRBativoexercicio.setSelected(true);
      JRBinativoexercicio.setSelected(false);
      BTalterarcadastro.setEnabled(true);
      habilitarCampos();
      
     }
          
          private void limparCampos(){

      TFCaminhovideo.setText("");
      TFGrupoMuscular.setText("");
      TFdescricaoexercicio.setText("");
      JRBativoexercicio.setSelected(false);
      JRBinativoexercicio.setSelected(false);      

    }
          
          private boolean verificarCampos(){

        if(!TFdescricaoexercicio.getText().trim().equals("")){
            return true;
        }
        JOptionPane.showMessageDialog(this,"INFORME O NOME DO EXERCÍCIO !","CDS ACADEMIA",JOptionPane.WARNING_MESSAGE);
        return false;

    }
          
          private void cadastraExercicio(){ 

         if(verificarCampos() ){ 

            ExercicioControl gc = new ExercicioControl();
            ExercicioBean gb = new ExercicioBean();

            gb.setCaminhovideo(TFCaminhovideo.getText().trim()); 
            gb.setDescricao(TFdescricaoexercicio.getText().trim()); 
            gb.setGrupomuscular(TFGrupoMuscular.getText().trim()); 
            if(JRBativoexercicio.isSelected()){ 
            gb.setStatus("ATIVO");
            }else if(JRBinativoexercicio.isSelected()){
            gb.setStatus("INATIVO");
            }else{
            JOptionPane.showMessageDialog(null,"INFORME O STATUS!","CDS ACADEMIA",JOptionPane.WARNING_MESSAGE);
            }

            gc.cadastraExercicio(gb);
            BTnovocadastro.setEnabled(true);
            limpaTabela();
            TFpesquisarexercicio.setText("");
            JOptionPane.showMessageDialog(null,"EXERCÍCIO CADASTRADO COM SUCESSO","MENSAGEM DO PROGRAMA",JOptionPane.INFORMATION_MESSAGE);
            desabilitarCampos();

         }
        }
          
          private void alteraExercicio(){

         if(verificarCampos() ){ 

            ExercicioControl gc = new ExercicioControl();
            ExercicioBean gb = new ExercicioBean();

            gb.setCaminhovideo(TFCaminhovideo.getText().trim()); 
            gb.setDescricao(TFdescricaoexercicio.getText().trim()); 
            gb.setGrupomuscular(TFGrupoMuscular.getText().trim());
            gb.setIdexercicio(exercicios.get(TBtabelaexercicio.getSelectedRow()).getIdexercicio()); 
            if(JRBativoexercicio.isSelected()){
            gb.setStatus("ATIVO");
            }else if(JRBinativoexercicio.isSelected()){
            gb.setStatus("INATIVO");
            }else{
            JOptionPane.showMessageDialog(null,"INFORME O STATUS!","CDS ACADEMIA",JOptionPane.WARNING_MESSAGE);
            }

            gc.alterarExercicio(gb);
            BTnovocadastro.setEnabled(true);
            limpaTabela();
            TFpesquisarexercicio.setText("");
            JOptionPane.showMessageDialog(null,"EXERCÍCIO ALTERADO COM SUCESSO","MENSAGEM DO PROGRAMA",JOptionPane.INFORMATION_MESSAGE);
            desabilitarCampos();

         }
        }
          
          private void excluirExercicio(){

        if(TBtabelaexercicio.getSelectedRow() != -1){
         int resposta = JOptionPane.showConfirmDialog(this,"Excluir Registro Selecionado ?","CONFIRMAÇÂO",JOptionPane.YES_NO_OPTION);
            if(resposta == JOptionPane.YES_OPTION){
                ExercicioControl gc = new ExercicioControl();
                gc.excluirExercicio(exercicios.get(TBtabelaexercicio.getSelectedRow()).getIdexercicio());
                limpaTabela();
                TFCaminhovideo.setText("");
                TFGrupoMuscular.setText("");
                TFdescricaoexercicio.setText("");
                TFpesquisarexercicio.setText("");

            }
        }
    }
          
          private void habilitarCampos(){

     TFCaminhovideo.setEditable(true);
     TFGrupoMuscular.setEditable(true);
     TFdescricaoexercicio.setEditable(true);
     JRBativoexercicio.setEnabled(true);
     JRBinativoexercicio.setEnabled(true);
     BTbuscarvideo.setEnabled(true);
   }

    private void desabilitarCampos(){

     TFCaminhovideo.setEditable(false);
     TFGrupoMuscular.setEditable(false);
     TFdescricaoexercicio.setEditable(false);
     JRBativoexercicio.setEnabled(false);
     JRBinativoexercicio.setEnabled(false);
     BTbuscarvideo.setEnabled(false);
  }
          
          
    /**
     * Creates new form TelaCadastroAluno
     */
    public TelaCadastroExercicio() {
        initComponents();
        defineRenderers();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jTextField1 = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jToggleButton1 = new javax.swing.JToggleButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        TFpesquisarexercicio = new javax.swing.JTextField();
        BTpesquisarexercicio = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        TFdescricaoexercicio = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jToolBar3 = new javax.swing.JToolBar();
        jPanel7 = new javax.swing.JPanel();
        JRBativoexercicio = new javax.swing.JRadioButton();
        JRBinativoexercicio = new javax.swing.JRadioButton();
        jLabel5 = new javax.swing.JLabel();
        TFGrupoMuscular = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        TFCaminhovideo = new javax.swing.JTextField();
        BTbuscarvideo = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        BTnovocadastro = new javax.swing.JButton();
        BTalterarcadastro = new javax.swing.JButton();
        BTsalvarcadastro = new javax.swing.JButton();
        BTexcluircadastro = new javax.swing.JButton();
        BTexcluircadastro2 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        TBtabelaexercicio = new javax.swing.JTable();

        jTextField1.setText("jTextField1");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Foto", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 127, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 140, Short.MAX_VALUE)
        );

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jToggleButton1.setText("jToggleButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("CADASTRO DE EXERCÍCIO");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        jLabel1.setFont(new java.awt.Font("Yu Gothic", 1, 14)); // NOI18N
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/exercicio 2.png"))); // NOI18N
        jLabel1.setText("CADASTRO DE EXERCÍCIO");

        TFpesquisarexercicio.setToolTipText("Digite o Nome do Exercício");

        BTpesquisarexercicio.setFont(new java.awt.Font("Yu Gothic", 0, 12)); // NOI18N
        BTpesquisarexercicio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Find.png"))); // NOI18N
        BTpesquisarexercicio.setText("Pesquisar");
        BTpesquisarexercicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTpesquisarexercicioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(TFpesquisarexercicio, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BTpesquisarexercicio)
                .addGap(18, 18, 18))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TFpesquisarexercicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BTpesquisarexercicio, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel13.setFont(new java.awt.Font("Yu Gothic", 0, 12)); // NOI18N

        jTabbedPane1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        TFdescricaoexercicio.setEditable(false);
        TFdescricaoexercicio.setToolTipText("Descrição do Exercício");

        jLabel4.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        jLabel4.setText("DESCRIÇÃO:");

        jToolBar3.setBackground(new java.awt.Color(255, 255, 255));
        jToolBar3.setFloatable(false);
        jToolBar3.setRollover(true);

        jPanel7.setBackground(new java.awt.Color(255, 255, 255));
        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "STATUS", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Yu Gothic", 1, 12))); // NOI18N

        JRBativoexercicio.setBackground(new java.awt.Color(255, 255, 255));
        JRBativoexercicio.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        JRBativoexercicio.setText("ATIVO");
        JRBativoexercicio.setToolTipText("Exercício Ativo");
        JRBativoexercicio.setEnabled(false);
        JRBativoexercicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRBativoexercicioActionPerformed(evt);
            }
        });

        JRBinativoexercicio.setBackground(new java.awt.Color(255, 255, 255));
        JRBinativoexercicio.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        JRBinativoexercicio.setText("INATIVO");
        JRBinativoexercicio.setToolTipText("Exercício Inativo");
        JRBinativoexercicio.setEnabled(false);
        JRBinativoexercicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRBinativoexercicioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JRBativoexercicio)
                    .addComponent(JRBinativoexercicio))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(JRBativoexercicio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JRBinativoexercicio)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jLabel5.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        jLabel5.setText("GRUPO MUSCULAR: ");

        TFGrupoMuscular.setEditable(false);
        TFGrupoMuscular.setToolTipText("Descrição do Exercício");

        jLabel6.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        jLabel6.setText("CAMINHO VIDEO:");

        TFCaminhovideo.setEditable(false);
        TFCaminhovideo.setToolTipText("Descrição do Exercício");

        BTbuscarvideo.setFont(new java.awt.Font("Yu Gothic", 0, 10)); // NOI18N
        BTbuscarvideo.setText("BUSCAR");
        BTbuscarvideo.setEnabled(false);
        BTbuscarvideo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTbuscarvideoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(58, 58, 58)
                        .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(TFCaminhovideo, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
                            .addComponent(TFdescricaoexercicio, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
                            .addComponent(TFGrupoMuscular))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BTbuscarvideo)))
                .addContainerGap(82, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(TFdescricaoexercicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(TFGrupoMuscular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(TFCaminhovideo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BTbuscarvideo))))
                .addGap(0, 11, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("EXERCÍCIO", jPanel3);

        jToolBar1.setBorder(null);
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        BTnovocadastro.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTnovocadastro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Add.png"))); // NOI18N
        BTnovocadastro.setText("Novo");
        BTnovocadastro.setFocusable(false);
        BTnovocadastro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTnovocadastro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTnovocadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTnovocadastroActionPerformed(evt);
            }
        });
        jToolBar1.add(BTnovocadastro);

        BTalterarcadastro.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTalterarcadastro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Modify.png"))); // NOI18N
        BTalterarcadastro.setText("Alterar");
        BTalterarcadastro.setFocusable(false);
        BTalterarcadastro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTalterarcadastro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTalterarcadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTalterarcadastroActionPerformed(evt);
            }
        });
        jToolBar1.add(BTalterarcadastro);

        BTsalvarcadastro.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTsalvarcadastro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Apply.png"))); // NOI18N
        BTsalvarcadastro.setText("Salvar");
        BTsalvarcadastro.setFocusable(false);
        BTsalvarcadastro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTsalvarcadastro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTsalvarcadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTsalvarcadastroActionPerformed(evt);
            }
        });
        jToolBar1.add(BTsalvarcadastro);

        BTexcluircadastro.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTexcluircadastro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Erase.png"))); // NOI18N
        BTexcluircadastro.setText("Excluir");
        BTexcluircadastro.setFocusable(false);
        BTexcluircadastro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTexcluircadastro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTexcluircadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTexcluircadastroActionPerformed(evt);
            }
        });
        jToolBar1.add(BTexcluircadastro);

        BTexcluircadastro2.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTexcluircadastro2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/No.png"))); // NOI18N
        BTexcluircadastro2.setText("Cancelar");
        BTexcluircadastro2.setFocusable(false);
        BTexcluircadastro2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTexcluircadastro2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTexcluircadastro2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTexcluircadastro2ActionPerformed(evt);
            }
        });
        jToolBar1.add(BTexcluircadastro2);

        TBtabelaexercicio.setFont(new java.awt.Font("Yu Gothic", 0, 12)); // NOI18N
        TBtabelaexercicio.setModel(tmExercicios);
        TBtabelaexercicio.setToolTipText("Exercícios");
        TBtabelaexercicio.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmExercicios = TBtabelaexercicio.getSelectionModel();
        lsmExercicios.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(!e.getValueIsAdjusting()){
                    tbExerciciosLinhaSelecionada(TBtabelaexercicio);
                }
            }
        });
        jScrollPane2.setViewportView(TBtabelaexercicio);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(616, Short.MAX_VALUE)
                .addComponent(jLabel13)
                .addGap(152, 152, 152))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 740, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(238, 238, 238)
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 740, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(139, 139, 139)
                .addComponent(jLabel13)
                .addContainerGap())
        );

        setSize(new java.awt.Dimension(784, 508));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void BTnovocadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTnovocadastroActionPerformed
    tipoCadastro = "novo"; 
    novoExercicio();
    habilitarCampos();
    JRBativoexercicio.setSelected(true); 
    }//GEN-LAST:event_BTnovocadastroActionPerformed

    private void BTpesquisarexercicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTpesquisarexercicioActionPerformed
        listarExercicios();
        limparCampos();
        novoExercicio();
        desabilitarCampos();
        BTnovocadastro.setEnabled(true);
        BTalterarcadastro.setEnabled(true);
    }//GEN-LAST:event_BTpesquisarexercicioActionPerformed

    private void BTsalvarcadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTsalvarcadastroActionPerformed
        if(tipoCadastro.equals("novo")){
        cadastraExercicio();
    }else if (tipoCadastro.equals("alteracao")){
        alteraExercicio();
    }
        limparCampos();  
    }//GEN-LAST:event_BTsalvarcadastroActionPerformed

    private void BTalterarcadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTalterarcadastroActionPerformed
         tipoCadastro = "alteracao";
         BTsalvarcadastro.setEnabled(true);
         habilitarCampos();     
    }//GEN-LAST:event_BTalterarcadastroActionPerformed

    private void BTexcluircadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTexcluircadastroActionPerformed
        excluirExercicio();
    }//GEN-LAST:event_BTexcluircadastroActionPerformed

    private void BTexcluircadastro2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTexcluircadastro2ActionPerformed
    novoExercicio();
    desabilitarCampos();
    BTalterarcadastro.setEnabled(true);
    BTnovocadastro.setEnabled(true);
    JRBativoexercicio.setSelected(false);
    }//GEN-LAST:event_BTexcluircadastro2ActionPerformed

    private void JRBativoexercicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRBativoexercicioActionPerformed
    if(JRBativoexercicio.isSelected()){
       JRBinativoexercicio.setSelected(false);    
    }
    }//GEN-LAST:event_JRBativoexercicioActionPerformed

    private void JRBinativoexercicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRBinativoexercicioActionPerformed
    if(JRBinativoexercicio.isSelected()){
   JRBativoexercicio.setSelected(false);
    }
    }//GEN-LAST:event_JRBinativoexercicioActionPerformed

    private void BTbuscarvideoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTbuscarvideoActionPerformed
buscaCaminho();
    }//GEN-LAST:event_BTbuscarvideoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroExercicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroExercicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroExercicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroExercicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaCadastroExercicio().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BTalterarcadastro;
    private javax.swing.JButton BTbuscarvideo;
    private javax.swing.JButton BTexcluircadastro;
    private javax.swing.JButton BTexcluircadastro2;
    private javax.swing.JButton BTnovocadastro;
    private javax.swing.JButton BTpesquisarexercicio;
    private javax.swing.JButton BTsalvarcadastro;
    private javax.swing.JRadioButton JRBativoexercicio;
    private javax.swing.JRadioButton JRBinativoexercicio;
    private javax.swing.JTable TBtabelaexercicio;
    private javax.swing.JTextField TFCaminhovideo;
    private javax.swing.JTextField TFGrupoMuscular;
    private javax.swing.JTextField TFdescricaoexercicio;
    private javax.swing.JTextField TFpesquisarexercicio;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar3;
    // End of variables declaration//GEN-END:variables
}
